#include "PrintUtilities.h"
#include "Utilities.h"
#include "Global.h"

#include "StlStringAndStreams.h"
#include "StlWrapper.h"

#include <cassert>

namespace Print
{
	static const size_t SCREEN_WIDTH = Consts::SCREEN_WIDTH;

	STL::string RightAl(const STL::string& msg)
	{
		STL::string temp;
		for (size_t i = msg.length(); i < SCREEN_WIDTH; ++i)
			temp += " ";
		return temp + msg;
	}

	STL::string Centred(const STL::string& msg)
	{
		STL::string temp;
		for (size_t i = 0; i < (SCREEN_WIDTH - msg.length()) / 2; ++i)
			temp += " ";
		return temp + msg;
	}

	STL::string CenterToLeft(const STL::string& msg)
	{
		STL::string temp;
		for (size_t i = msg.length(); i < (SCREEN_WIDTH / 2); ++i)
			temp += " ";
		return temp + msg;		
	}

	void ClearScreen()
	{
		system("cls");
	}

	void PrintDecorationLine(STD::ostream& o_stream, const char i_char)
	{
		o_stream << STL::string(SCREEN_WIDTH - 1, i_char);
	}

	void ResetInput()
	{
		if(!STD::cin)
		{
			STD::cin.clear();
			STD::cin.ignore(1000, '\n');
			STD::cin.ignore(1000, ' ');
		}
	}

	STL::string Title(const STL::string& i_title)
	{
		static bool first_time = true;
		static STL::string header;
		if(first_time)
		{
			const STL::string titleBorder  = "/\\";
			for (size_t i = header.length(); i < SCREEN_WIDTH/titleBorder.size() - 1; ++i)
				header += titleBorder;
			header += "\n";
			first_time = false;
		}

		return header + i_title + "\n" + header + "\n";
	}

	STL::string Options(const STL::string& i_options)
	{
		const char optionBorder = '=';
		static bool first_time = true;
		static STL::string header("==OPTIONS:");
		static STL::string footer(SCREEN_WIDTH+2, optionBorder);
		if(first_time)
		{
			header.append(SCREEN_WIDTH-header.length()+1, optionBorder);
			header[SCREEN_WIDTH] = '\n';
			footer[0] = '\n';
			footer[SCREEN_WIDTH+1] = '\n';
			first_time = false;
		}

		return header + i_options + footer;
	}

	const STL::string& SeparatorLine()
	{
		static bool first_time = true;
		static STL::string temp(SCREEN_WIDTH+2, '-');
		if(first_time)
		{
			temp[0] = '\n';
			temp[SCREEN_WIDTH+1] = '\n';
			first_time = false;
		}
		return temp;
	}

}
